<script>
	export default {
		onLaunch: function() {
			console.log('App Launch')
		},
		onShow: function() {
			console.log('App Show')
		},
		onHide: function() {
			console.log('App Hide')
		},
		globalData: {
			platform: '',
			systemLevel: '',
			equipmentNumber: '',
			userInfo: {},
			canlisten:false,
			appinfo:{}
		},
		onLaunch: function() {
			let that = this;
			uni.getSystemInfo({
				success: e => {
					console.log(this.globalData);
					// #ifdef APP-PLUS
					if (e.platform == 'android') {
						this.globalData.platform = 'android'
						this.globalData.systemLevel = e.system
						if (e.system < 10) {
							plus.device.getInfo({
								success: e => {
									console.log(e);
									//这里获取到imei 剩下的逻辑也写在这里面
									var a = e.imei.indexOf(",")
									if (a < 0) {
										this.globalData.equipmentNumber = e.imei
									} else {
										this.globalData.equipmentNumber = e.imei.substring(0, a);
									}
									//里面写接下来的逻辑
									console.log('imei=' + imei); //这里是能获取imei的
								}
							})
						} else {
							plus.device.getOAID({
								success: e => {
									console.log('getOAID success: ' + e.oaid);
									this.globalData.equipmentNumber = e.oaid;
								}
							});
						}
					} else {
						this.globalData.platform = 'ios';
						this.globalData.systemLevel = e.system;
						this.globalData.equipmentNumber = idfa.value()
					};
					// #endif
				}
			})
			//获取官方邀请码
			this.$u.api.getConfig({
				key: 'official_invitation_code,open_site_domain',
			}).then((res) => {
				if (res.code == 200){
					this.$u.vuex('official_invitation_code', res.data.official_invitation_code);
					this.$u.vuex('site_domain', res.data.open_site_domain);
				}
				// console.info('------111111--------')
				// console.info(this.$u.vuex.official_invitation_code)
				// console.info(this.$store.state);
				// console.info(this.$store.state.official_invitation_code);
				// console.info(this.$u.vuex.official_invitation_code);
				// console.info(this.official_invitation_code);
			})
			//获取app信息
			this.$u.api.getConfig({
				key: 'open_app_name,open_app_logo,open_app_download_qr,open_app_download_url,open_app_summary',
			}).then((res) => {
				debugger
				if (res.code == 200){
					var info = {};
					info.appName = res.data.open_app_name;
					info.logo = res.data.open_app_logo;
					info.downloadQr = res.data.open_app_download_qr;
					info.download = res.data.open_app_download_url;
					info.appSummary = res.data.open_app_summary;
					this.globalData.appinfo = info;
					this.$u.vuex('appInfo',  info);
				}
				// console.info('------111111--------')
				// console.info(this.$u.vuex.official_invitation_code)
				// console.info(this.$store.state);
				// console.info(this.$store.state.official_invitation_code);
				// console.info(this.$u.vuex.official_invitation_code);
				// console.info(this.official_invitation_code);
			})
			//#ifdef H5
			//获取邀请码
			let width = window.screen.width;
			if (window.location.href.indexOf('?invitation=') !== -1 || window.location.href.indexOf('&invitation=') !== -1) {
				if (window.location.href.indexOf('?invitation=') !== -1) {
					this.$u.vuex('invitation', window.location.href.split('?invitation=')[1].split('&')[0]);
				} else {
					this.$u.vuex('invitation', window.location.href.split('&invitation=')[1].split('&')[0]);
				}
			}
			//#endif
			
			//#ifdef H5
			//判断浏览器
			let url = encodeURIComponent(window.location.href.split('#')[0]);
			//邀请码
			let invitation = this.$u.vuex.official_invitation_code;
			
			if (window.location.href.indexOf('?invitation=') !== -1 || window.location.href.indexOf('&invitation=') !== -1) {
				if (window.location.href.indexOf('?invitation=') !== -1) {
					invitation = window.location.href.split('?invitation=')[1].split('&')[0];
					this.$u.vuex('invitation', invitation);
				} else {
					invitation = window.location.href.split('&invitation=')[1].split('&')[0];
					this.$u.vuex('invitation', invitation);
				}
			}
			let ua = navigator.userAgent.toLowerCase();
			//是否微信打开
			if (ua.indexOf('micromessenger') !== -1) {
				let openid = this.$u.vuex.openId;
				if (!openid) {
					if (window.location.href.indexOf('?code=') !== -1 || window.location.href.indexOf('&code=') !== -1) {
						let code;
						if (window.location.href.indexOf('?code=') !== -1) {
							code = window.location.href.split('?code=')[1].split('&')[0];
						} else {
							code = window.location.href.split('&code=')[1].split('&')[0];
						}
					} else {
						window.location.href =
							'https://open.weixin.qq.com/connect/oauth2/authorize?appid=' +
							this.$queue.getWxAppid() +
							'&redirect_uri=' +
							window.location.href.split('#')[0] +
							'&response_type=code&scope=snsapi_userinfo#wechat_redirect';
					}
				} else {

				}
			}
			//#endif
		},
		methods: {

		}
	}
</script>

<style lang="scss">
	/*每个页面公共css */
	@import url('./static/css/index.css');
	@import "uview-ui/index.scss";
	@import url('./static/css/iconfont.css');
</style>
